﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SE560Multimedia.src;

namespace SE560Multimedia.pages
{
    public partial class WebForm6 : System.Web.UI.Page
    {
        private SessionManager sessionManager;

        protected void Page_Load(object sender, EventArgs e)
        {
            sessionManager = new SessionManager(Session);

            ProjectDataSetTableAdapters.mediaTableAdapter mediaTableAdapter =
                new ProjectDataSetTableAdapters.mediaTableAdapter();

            ProjectDataSet.mediaDataTable playlistResult =
                mediaTableAdapter.GetDataByDescendingMediaID(sessionManager.SessionLoggedUserId);

            sessionManager.PlaylistResult = playlistResult;

            GridViewRecentlyAdded.DataSource = playlistResult;
            GridViewRecentlyAdded.DataBind();
        }

        protected void GridViewSearchResult_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "ResultListPlayCommand")
            {
                int rowId = Convert.ToInt32(e.CommandArgument);
                sessionManager.CurrentDataRow =
                    sessionManager.PlaylistResult[rowId];
                System.Web.HttpContext.Current.Response.Redirect(
                    SessionManager.PLAY_PAGE_ADDESS);
            }
        }
    }
}
